<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for coa/lib/coaparam.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../prettify.css" />
    <link rel="stylesheet" href="../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../index.html">All files</a> / <a href="index.html">coa/lib</a> coaparam.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">51.61% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>16/31</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/8</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">55.56% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>5/9</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">51.61% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>16/31</span>
      </div>
    </div>
  </div>
  <div class='status-line medium'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">32x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">32x</span>
<span class="cline-any cline-yes">32x</span>
<span class="cline-any cline-yes">32x</span>
<span class="cline-any cline-yes">32x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">9x</span>
<span class="cline-any cline-yes">9x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
&nbsp;
const fs = require('fs');
&nbsp;
const CoaObject = require('./coaobject');
&nbsp;
/**
 * COA Parameter
 *
 * Base class for options and arguments
 *
 * --------|-----|-----|-----
 *         | Cmd | Opt | Arg
 * --------|-----|-----|-----
 *  arr    |     | ✓   | ✓
 *  req    |     | ✓   | ✓
 *  val    |     | ✓   | ✓
 *  def    |     | ✓   | ✓
 *  input  |     | ✓   | ✓
 *  output |     | ✓   | ✓
 *
 * @class CoaParam
 * @extends CoaObject
 */
module.exports = class CoaParam extends CoaObject {
    constructor(cmd) {
        super(cmd);
&nbsp;
        this._arr = false;
        this._req = false;
        this._val = undefined;
        this._def = undefined;
    }
&nbsp;
    /**
     * Makes a param accepts multiple values.
     * Otherwise, the value will be used by the latter passed.
     *
     * @returns {COA.CoaParam} - this instance (for chainability)
     */
    arr() {
        this._arr = true;
        return this;
    }
&nbsp;
    /**
     * Makes a param required.
     *
     * @returns {COA.CoaParam} - this instance (for chainability)
     */
    req() {
        this._req = true;
        return this;
    }
&nbsp;
    /**
     * Set a validation (or value) function for param.
     * Value from command line passes through before becoming available from API.
     * Using for validation and convertion simple types to any values.
     *
     * @param {Function} val - validating function,
     *         invoked in the context of option instance
     *         and has one parameter with value from command line.
     * @returns {COA.CoaParam} - this instance (for chainability)
     */
    val(val) {
        this._val = val;
        return this;
    }
&nbsp;
    /**
     * Set a default value for param.
     * Default value passed through validation function as ordinary value.
     *
     * @param {*} def - default value of function generator
     * @returns {COA.CoaParam} - this instance (for chainability)
     */
    def(def) {
        this._def = def;
        return this;
    }
&nbsp;
    /**
     * Make option value inputting stream.
     * It's add useful validation and shortcut for STDIN.
     *
     * @returns {COA.CoaParam} - this instance (for chainability)
     */
<span class="fstat-no" title="function not covered" >    in</span>put() {
<span class="cstat-no" title="statement not covered" >        process.stdin.pause();</span>
<span class="cstat-no" title="statement not covered" >        return this</span>
            .def(process.stdin)
            .val(<span class="fstat-no" title="function not covered" >fu</span>nction(v) {
<span class="cstat-no" title="statement not covered" >                if(typeof v !== 'string')</span>
<span class="cstat-no" title="statement not covered" >                    return v;</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >                if(v === '-')</span>
<span class="cstat-no" title="statement not covered" >                    return process.stdin;</span>
&nbsp;
                const s = <span class="cstat-no" title="statement not covered" >fs.createReadStream(v, { encoding : 'utf8' });</span>
<span class="cstat-no" title="statement not covered" >                s.pause();</span>
<span class="cstat-no" title="statement not covered" >                return s;</span>
            });
    }
&nbsp;
    /**
     * Make option value outputing stream.
     * It's add useful validation and shortcut for STDOUT.
     *
     * @returns {COA.CoaParam} - this instance (for chainability)
     */
<span class="fstat-no" title="function not covered" >    ou</span>tput() {
<span class="cstat-no" title="statement not covered" >        return this</span>
            .def(process.stdout)
            .val(<span class="fstat-no" title="function not covered" >fu</span>nction(v) {
<span class="cstat-no" title="statement not covered" >                if(typeof v !== 'string')</span>
<span class="cstat-no" title="statement not covered" >                    return v;</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >                if(v === '-')</span>
<span class="cstat-no" title="statement not covered" >                    return process.stdout;</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >                return fs.createWriteStream(v, { encoding : 'utf8' });</span>
            });
    }
};
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Feb 17 2017 22:25:28 GMT+0300 (MSK)
</div>
</div>
<script src="../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../sorter.js"></script>
</body>
</html>
